package com.jwthhealth_pub.old.physicalfitness.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.physicalfitness.view.PhysicalFitnessAnswerActivity;

/**
 * Created by Administrator on 2016/12/20.
 */
public class phesicalFitnessAnswerAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private boolean theAnswer;

    public phesicalFitnessAnswerAdapter(PhysicalFitnessAnswerActivity physicalFitnessAnswerActivity, boolean answer) {
        this.mContext = physicalFitnessAnswerActivity;
        this.theAnswer = answer;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        if (viewType == ITEM_TYPE.ITEM_HEAD.ordinal()) {
            return new HeadViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_physical_answer_head, parent, false));
        } else if (viewType == ITEM_TYPE.ITEM_BODY.ordinal()) {
            return new BodyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_physical_answer_body, parent, false));
        } else {
            return new FootViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_physical_answer_foot, parent, false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (theAnswer) {
            if (position == 0) {
                HeadViewHolder headViewHolder = (HeadViewHolder) holder;
                headViewHolder.headTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_yes));
            } else if (position == 4){
                FootViewHolder footViewHolder = (FootViewHolder) holder;
                footViewHolder.footDescribe.setText(mContext.getResources().getString(R.string.physicalfiness_answer_attention));
            } else {
                BodyViewHolder bodyViewHolder = (BodyViewHolder) holder;
                if (position == 1) {
                    bodyViewHolder.describeTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_yes_body_one));
                    bodyViewHolder.describeTwoTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_yes_body_two));
                } else if (position == 2) {
                    bodyViewHolder.describeTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_yes_body_thi));
                    bodyViewHolder.describeTwoTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_yes_body_for));
                } else if (position == 3) {
                    bodyViewHolder.describeTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_yes_body_fiv));
                    bodyViewHolder.describeTwoTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_yes_body_six));
                }
            }
        } else {
            if (position == 0) {
                HeadViewHolder headViewHolder = (HeadViewHolder) holder;
                headViewHolder.headTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_no));
            } else if (position == 4){
                FootViewHolder footViewHolder = (FootViewHolder) holder;
                footViewHolder.footDescribe.setText(mContext.getResources().getString(R.string.physicalfiness_answer_attention));
            } else {
                BodyViewHolder bodyViewHolder = (BodyViewHolder) holder;
                if (position == 1) {
                    bodyViewHolder.describeTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_no_body_one));
                    bodyViewHolder.describeTwoTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_no_body_two));
                } else if (position == 2) {
                    bodyViewHolder.describeTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_no_body_thi));
                    bodyViewHolder.describeTwoTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_no_body_for));
                } else if (position == 3) {
                    bodyViewHolder.describeTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_no_body_fiv));
                    bodyViewHolder.describeTwoTv.setText(mContext.getResources().getString(R.string.physicalfiness_answer_no_body_six));
                }
            }
        }
    }

    @Override
    public int getItemCount() {
        if (theAnswer){
            return 5;
        } else {
            return 5;
        }
    }

    @Override
    public int getItemViewType(int position) {

        if (theAnswer) {
            if (position == 0){
                return ITEM_TYPE.ITEM_HEAD.ordinal();
            } else if (position == 4){
                return ITEM_TYPE.ITEM_FOOT.ordinal();
            } else {
                return ITEM_TYPE.ITEM_BODY.ordinal();
            }

        } else {
            if (position == 0){
                return ITEM_TYPE.ITEM_HEAD.ordinal();
            } else if (position == 4){
                return ITEM_TYPE.ITEM_FOOT.ordinal();
            } else {
                return ITEM_TYPE.ITEM_BODY.ordinal();
            }
        }
    }

    private class HeadViewHolder extends RecyclerView.ViewHolder{

        TextView headTv;

        public HeadViewHolder(View itemView) {
            super(itemView);
            headTv = (TextView) itemView.findViewById(R.id.tv_answer_head);
        }
    }

    class BodyViewHolder extends RecyclerView.ViewHolder{

        TextView describeTv, describeTwoTv;

        public BodyViewHolder(View itemView) {
            super(itemView);
            describeTv = (TextView) itemView.findViewById(R.id.tv_answer_describe);
            describeTwoTv = (TextView) itemView.findViewById(R.id.tv_answer_describe_two);
        }
    }

    class FootViewHolder extends RecyclerView.ViewHolder{

        TextView footDescribe;

        public FootViewHolder(View itemView) {
            super(itemView);
            footDescribe = (TextView) itemView.findViewById(R.id.tv_foot_describe);
        }
    }

    private enum ITEM_TYPE {
        ITEM_HEAD, ITEM_BODY, ITEM_FOOT;
    }
}
